package org.example.controller;


import org.example.model.Teacher;
import org.example.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class TeacherController {
    @Autowired
    private TeacherService teacherService;
    @RequestMapping(value = "/queryTeacher")
    public List<Teacher> queryTeacherList(){
        //1.调用业务逻辑层中的查询方法
        List<Teacher> teacherList = teacherService.queryTeacher();
        //2.返回查询结果
        return teacherList;
    }


    @PostMapping(value = "/addTeacher")
    public int addTeacher(@RequestBody Teacher teacher){
        //调用业务逻辑层中的方法，实现添加操作
        return teacherService.addTeacher(teacher);
        }

    /**
     * 功能：根据教师编号修改教师信息
     * @param teacher
     */
    @RequestMapping("/updateTeacher")
    public int updateTeacher(@RequestBody Teacher teacher){
        //调用业务逻辑层中的修改方法
        return teacherService.updateTeacher(teacher);
    }

    @RequestMapping("/deleteTeacherById")
    public int deleTeacherById(int tId){
        return teacherService.deleteTeacher(tId);
    }

    @RequestMapping("/queryTeacherDept")
    public List<Map<String ,Object>> queryTeacherDept(){
        return teacherService.queryTeacherDept();
    }

    @RequestMapping("/queryTeacherByID")
    public Teacher queryTeacherByID(int tId){
        return teacherService.queryTeacherById(tId);
    }


}
